/**
 * 奖惩规则变更记录 编辑页
 *
 * 作者 admin
 * 日期 2024-08-08 13:20:30
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#peccancyClauseRuleRecord-edit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (peccancyClauseRuleRecordData) {
            form.val("peccancyClauseRuleRecord-edit-form", {
                "clauseRuleRecordId": peccancyClauseRuleRecordData.clauseRuleRecordId,
                "clauseRuleId": peccancyClauseRuleRecordData.clauseRuleId,
                "changeTime": peccancyClauseRuleRecordData.changeTime,
                "changeType": peccancyClauseRuleRecordData.changeType,
                "beforeJson": peccancyClauseRuleRecordData.beforeJson,
                "afterJson": peccancyClauseRuleRecordData.afterJson,
            });
        }
    }

    form.on('submit(peccancyClauseRuleRecord-edit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        if (data.clauseRuleRecordId && data.clauseRuleRecordId.length > 0) {
            febs.postArray(ctx + 'peccancyClauseRuleRecord/update', data, function () {
                layer.closeAll();
                febs.alert.success('修改成功');
                febs.reloadPage();
            });
        } else {
            febs.postArray(ctx + 'peccancyClauseRuleRecord', data, function () {
                layer.closeAll();
                febs.alert.success('新增成功');
                $('#febs-peccancyClauseRuleRecord').find('#query').trigger('click');
            });
        }
    }
});